package Servlet.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Creche.Personne.Personne;
import Form.DemandeForm;

@SuppressWarnings("serial")
public class Demande extends HttpServlet {
	
	public static final String URL_REDIRECTION = "succesInscript.jsp";
	public static final String VUE = "/WEB-INF/demande.jsp";
    public static final String PERS = "pers";
    public static final String FORM = "form";
    
    
    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
    		throws ServletException, IOException {
    	
        /* Affichage de la page demande */
        this.getServletContext().getRequestDispatcher( VUE ).forward(req, resp);
    }
    
    
    public void doPost(HttpServletRequest req, HttpServletResponse resp) 
    		throws ServletException, IOException {
    	
    	DemandeForm form = new DemandeForm();
    	Personne pers = form.inscrirePers(req);
    	
    	if (form.getErreurs().isEmpty() && !form.getInscrit()) {
    		resp.sendRedirect(URL_REDIRECTION);
    		
        }
         
        req.setAttribute(FORM, form);
        req.setAttribute(PERS, pers);
        
        /* Transmission de la paire d'objets request/response à notre JSP */
        this.getServletContext().getRequestDispatcher( VUE ).forward(req, resp);
    }

}
